package winOrDie.GameEngine.Server;

import winOrDie.Net.P2P.WoD_Scribe_Channel;
import winOrDie.Net.Server.WoD_Server_Client_List;
import winOrDie.Net.Server.WoD_Server_ControlChannel;
import winOrDie.Net.Server.WoD_Server_ControlChannel_Event;
import winOrDie.Net.Server.WoD_Server_ControlChannel_Listener;
import winOrDie.Net.Server.WoD_Server_RT;
import winOrDie.Net.Server.WoD_Server_RT_Event;
import winOrDie.Net.Server.WoD_Server_RT_Listener;
import winOrDie.Net.Server.WoD_TCP_Socket_Server;
import winOrDie.Net.Server.WoD_TCP_Socket_Server_Event;
import winOrDie.Net.Server.WoD_TCP_Socket_Server_Listener;


public class WoD_Server 
implements WoD_TCP_Socket_Server_Listener, WoD_Server_ControlChannel_Listener, WoD_Server_RT_Listener
{

	public static final int bufferSize = 800; 
	
	
	private int port_UDP_RT = -1;
	private int port_TCP_CONTROL = -1;
	
	
	private WoD_Server_Client_List clientList = new WoD_Server_Client_List();

	/**
	 * {@link WoD_TCP_Socket_Server} object used for TCP mode
	 */
	private WoD_TCP_Socket_Server woD_TCP_Socket_Server = null;
	
	/**
	 * {@link WoD_Server_ControlChannel} object used for Scribe mode
	 */
	private WoD_Server_ControlChannel woDServerControlChannel = null;
	
	/**
	 * {@link WoD_Server_RT} object used for real time
	 */
	private WoD_Server_RT woDServerRT = null;
	
	public int getPort_UDP_RT() {
		return port_UDP_RT;
	}


	public void setPort_UDP_RT(int portUDPRT) {
		port_UDP_RT = portUDPRT;
	}


	public int getPort_TCP_CONTROL() {
		return port_TCP_CONTROL;
	}


	public void setPort_TCP_CONTROL(int portTCPCONTROL) {
		port_TCP_CONTROL = portTCPCONTROL;
	}


	public WoD_Server(int port_TCP_CONTROL, int port_UDP_RT) {
		
		this.port_TCP_CONTROL = port_TCP_CONTROL;
		this.port_UDP_RT = port_UDP_RT;
		
		
		woD_TCP_Socket_Server = new WoD_TCP_Socket_Server(port_TCP_CONTROL);
		woD_TCP_Socket_Server.add_WoD_TCP_Socket_Server_Listener(this);
	}
	
	
	
	public WoD_Server_ControlChannel getWoDServerControlChannel() {
		return woDServerControlChannel;
	}


	/**
	 * Construct new {@link WoD_Server} from {@link WoD_Scribe_Channel}, {@link WoD_Server_Client_List} and UDP_port passed
	 * as parameters
	 * @param woDScribeChannel
	 * @param clientList
	 * @param port_UDP_RT
	 */
	public WoD_Server(
			WoD_Scribe_Channel woDScribeChannel, 
			WoD_Server_Client_List clientList,
			int port_UDP_RT
			) 
	{
		this.port_UDP_RT = port_UDP_RT;
		
		/**
		 * Set WoD_Scribe_Channel object
		 */
		woDServerControlChannel = new WoD_Server_ControlChannel(woDScribeChannel);
		woDServerControlChannel.add_WoD_Server_ControlChannel_Listener(this);
		
		/**
		 * Set WoD_Scribe_Channel object
		 */
		woDServerRT = new WoD_Server_RT(port_UDP_RT, bufferSize, 0);
		woDServerRT.add_WoD_Server_RT_Listener(this);
		
		
		this.clientList = clientList;
	}
	
	
	public void notify_Event_WoD_TCP_Socket_Server(WoD_TCP_Socket_Server_Event event) {
		switch (event.getEvent_Type()) {
		case WoD_TCP_Socket_Server_Event.NEW_CLIENT:
			
			
			break;
			
		case WoD_TCP_Socket_Server_Event.SERVER_ERROR:
			
			break;

		default:
			break;
		}
		
	}
	
	public void notify_Event_WoD_Client_ControlChannel(WoD_Server_ControlChannel_Event event) 
	{
		switch (event.getEvent_Type()) {
		case WoD_Server_ControlChannel_Event.JOIN_GAME:
			
			
			
			break;

		default:
			break;
		}
		
	}
	
	
	@Override
	public void notify_Event_WoD_Server_RTChannel(WoD_Server_RT_Event event) {
		switch (event.getEvent_Type()) {
		case WoD_Server_RT_Event.GAME_ACTION:
			
			break;

		default:
			break;
		}
		
	}
	
}
